package com.etymgiko.lyricshere.web;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

/**
 *
 * @author Ivan Holub
 */
public class UrlParser {

    public static final String ARTIST_PATTERN = "/lyrics/([^/]*)";

    public static final String SONG_PATTERN = "/lyrics/([^/]*)/([^/]*)";

    public static String parseArtist(String url) {
        String retValue = null;
        Pattern p = Pattern.compile(ARTIST_PATTERN);
        Matcher m = p.matcher(url);
        if (m.matches()) {
            retValue = m.group(1);
        }
        return retValue;
    }

    public static SongUrl parseSong(String url) {
        SongUrl retValue = null;
        Pattern p = Pattern.compile(SONG_PATTERN);
        Matcher m = p.matcher(url);
        if (m.matches()) {
            retValue = new SongUrl(m.group(1), m.group(2));
        }
        return retValue;
    }

}
